package com.itheima.controller.backend.security;

import com.github.pagehelper.Page;
import com.itheima.Service.CheckItemService;
import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("checkitem")
@Slf4j
public class CheckItemController {
    @Autowired
    private CheckItemService checkItemService;

    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        log.info("新增检查项");
        checkItemService.add(checkItem);
        return new  Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS,null);
    }

    @GetMapping("delete")
    public Result delete(@RequestParam Integer id){
        log.info("根据id删除检查项");
        checkItemService.delete(id);
        return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS, null);
    }

    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId(@RequestParam Integer checkgroupId){
        log.info("根据检查组id查询检查项id集合");
        List<Integer>reuslt =checkItemService.findCheckItemIdsByCheckGroupId(checkgroupId);
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, reuslt);
    }

    @PostMapping("edit")
    public Result edit(@RequestBody CheckItem checkItem){
        log.info("编辑");
        checkItemService.edit(checkItem);
        return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS,null );
    }

    @PostMapping("/findpage")
    public Result findById(@RequestBody QueryPageBean page){
        log.info("分页查询检查项");
       PageResult pageResult = checkItemService.findPage(page);
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, pageResult);
    }

    @GetMapping("findAll")
    public Result findAll(){
        log.info("查询所有检查项");
        List<CheckItem> list = checkItemService.findAll();
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS, list);
    }

    @GetMapping("findById")
    public Result select(@RequestParam Integer id){
        log.info("根据id查询检查项");
        CheckItem checkItem=checkItemService.findById(id);
        return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem );
    }
}
